package com.xueyu.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * 数据库连接类
 * 
 * @author xueyu
 *
 */
public class DbUtil {
	private String dbUrl = "jdbc:mysql://localhost:3306/db_book";
	private String dbUserName = "root";
	private String dbPassword = "123";
	private String jdbcName = "com.mysql.jdbc.Driver";
	/**
	 * 获取数据库连接
	 * @return 数据库连接Connection
	 * @throws Exception
	 */
	public Connection getCon() throws Exception {
		Class.forName(jdbcName);
		Connection con = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
		return con;
	}

	/**
	 * 关闭数据库连接
	 * 
	 * @param con
	 * @throws SQLException
	 */
	public void closeCon(Connection con) throws SQLException {
		if (con != null) {
			con.close();
		}
	}

}
